function BigNumber(num, size) {
    this.size = size || 1000;
    this.pool = [];
    var tmp=num, tmp1;
    do {
        tmp1 = tmp%this.size;
        this.pool.push(tmp1);
        tmp = (tmp-tmp1)/this.size;
    } while(tmp>0);
}

BigNumber.prototype.time = function(a) {
    
    var tmp = 0, tmp1;
    for(var i=0; i<this.pool.length; i++) {
        var p = this.pool[i]*a + tmp;
        var tmp = p%this.size;
        this.pool[i] = tmp;
        tmp = (p-tmp)/this.size;
    }
    if(tmp) {
        do {
            tmp1 = tmp%this.size;
            this.pool.push(tmp1);
            tmp = (tmp-tmp1)/this.size;
        } while(tmp>0);    
    }
};

BigNumber.prototype.sumDigital = function() {
    var sum=0;
    for(var i=0; i<this.pool.length; i++) {
        var tmp=this.pool[i];
        do {
            tmp1 = tmp%10;
            sum += tmp1;
            tmp = (tmp-tmp1)/10;
        }while(tmp>0);
    }
    return sum;
}

var max=0;
for (var a=1; a<100; a++) {
    var p=new BigNumber(a);
    for(var b=1; b<100; b++) {
        p.time(a);
        var tmp = p.sumDigital();
        if(tmp>max) {
            max = tmp;
            print(max);
        }
        
    }
}
